package com.pluszg.nutrition.model.product;

import com.pluszg.nutrition.common.bean.BaseModel;
import lombok.Getter;
import lombok.Setter;

import java.math.BigDecimal;


/**
 * plus_product 商品表
 *
 * @author Plus
 * @version 1.0
 * @date 2020-04-29 21:21:36
 * @company pluszg
 */
@SuppressWarnings("serial")
@Setter
@Getter
public class Product extends BaseModel {

    /**
     * id
     */
    private String id;

    /**
     * 商品编码
     */

    private String productCode;

    /**
     * 商品名称
     */

    private String productName;

    /**
     * 库存数量
     */

    private Integer count;

    /**
     * 商品价格
     */

    private BigDecimal price;


    public String toString() {
        return new StringBuilder().append("Product{").
                append("id=").append(id).
                append(",productCode=").append(productCode).
                append(",productName=").append(productName).
                append(",count=").append(count).
                append(",price=").append(price).
                append('}').toString();
    }

    /**
     * 复制字段：
     * id, productCode, productName, count,
     * price
     */
    public Product copy() {
        Product product = new Product();
        product.id = this.id;
        product.productCode = this.productCode;
        product.productName = this.productName;
        product.count = this.count;
        product.price = this.price;
        return product;
    }

    /**
     * 比较字段：
     * id, productCode, productName, count,
     * price
     */
    public boolean test(Product t) {
        if (t == null) return false;
        return (this.id == null || this.id.equals(t.id))
                && (this.productCode == null || this.productCode.equals(t.productCode))
                && (this.productName == null || this.productName.equals(t.productName))
                && (this.count == null || this.count.equals(t.count))
                && (this.price == null || this.price.equals(t.price))
                ;
    }

    public void update(Product element) {
        if (element == null)
            return;
        if (this.id != null && !this.id.isEmpty()) {
            element.id = this.id;
        }
        if (this.productCode != null && !this.productCode.isEmpty()) {
            element.productCode = this.productCode;
        }
        if (this.productName != null && !this.productName.isEmpty()) {
            element.productName = this.productName;
        }
        if (this.count != null) {
            element.count = this.count;
        }
        if (this.price != null) {
            element.price = this.price;
        }
    }
}
